@extends('admin.layouts.app')
@section('content')

                        <!-- Page-Title -->
                        <div class="row">
                            <div class="col-sm-12">
                                <h4 class="page-title">用户管理</h4>
                                <ol class="breadcrumb">
                                    <li><a href="{{url('zadmin/')}}">系统</a></li>
                                   
                                    <li class="active">新增用户</li>
                                </ol>
                            </div>
                        </div>
                        
                        <div class="row">
                        	<div class="col-lg-12">
                        		<div class="card-box">
                            <h2 class="m-t-0 header-title">新增用户</h2>
                            <hr/>
                             @if(session('rs'))
                              <div class="alert alert-{{session('rs')['status']}}">
                                {{ session('rs')['msg'] }}
                              </div>
                              @endif
                        			<div class="row">
			                        	<div class="col-md-9">
                                  <form class="form-horizontal" role="form" action="{{url('zadmin/users/')}}" method="post" enctype="multipart/form-data">
                                    <div class="form-group">
                                                  <label class="col-md-2 control-label">账号</label>
                                                  <div class="col-md-10">
                                                      <input type="text" class="form-control" name="username" value="" required="">
                                                  </div>
                                              </div>
                                              <div class="form-group">
                                                  <label class="col-md-2 control-label">真实姓名</label>
                                                  <div class="col-md-10">
                                                      <input type="text" class="form-control" name="truename" value="" required="">
                                                  </div>
                                              </div>
                                               <div class="form-group">
                                                  <label class="col-md-2 control-label">手机号码</label>
                                                  <div class="col-md-10">
                                                      <input type="text" class="form-control" name="phone" value="" required="">
                                                  </div>
                                              </div>
                                              <div class="form-group">
                                                  <label class="col-md-2 control-label">密码</label>
                                                  <div class="col-md-10">
                                                      <input type="password" class="form-control" name="password" value="" >
                                                  </div>
                                              </div>
                                              <div class="form-group">
                                                  <label class="col-md-2 control-label">密码确认</label>
                                                  <div class="col-md-10">
                                                      <input type="password" class="form-control" name="password2" value="">
                                                  </div>
                                              </div>
                                             
  <div class="form-group">
                    <label class="col-md-2 control-label">角色</label>
                    <div class="col-md-8">
                      <select class="form-control" name="role_code" id="role_code">
                        <option value="">请选择角色</option>
                        @foreach($roles as $role)
                        <option value="{{$role->code}}">{{$role->name}}</option>
                        @endforeach
                      </select>                                      
                    </div> 
                     <div class="col-md-2">
                        <button type="button" class="btn btn-warning" id="add-role">新增角色</button>
                                                  </div>                      
                  </div>                                            
                  <div class="form-group">
                    <label class="col-md-2 control-label">绑定公众号用户</label>
                    <div class="col-md-10">
                      <select name="openid" class="form-control select2"  >
                        <option value="">请选择</option>
                      @foreach($wxUsers as $wxuser)
                      <option   value="{{$wxuser->openid}}" >{{$wxuser->nickname}}</option>
                      @endforeach   
                      </select>                                    
                    </div>                       
                  </div>

                  <div class="form-group">
                    <label class="col-md-2 control-label">绑定小程序用户</label>
                    <div class="col-md-10">
                      <select name="small_openid" class="form-control select2" >
                        <option value="">请选择</option>
                      @foreach($smallUsers as $su)
                      <option   value="{{$su->small_openid}}" >{{$su->nickname}}</option>
                      @endforeach   
                      </select>                                    
                    </div>                       
                  </div>
                                            
                                              
                        
                                              <div class="form-group text-center">
                                                  
                                                  <button type="submit" class="btn btn-info waves-effect waves-light">保存</button>
                                              </div>
                                              
                                              
                             {{csrf_field()}}
                                          </form>
                                </div>
			                        	
			                        </div>

                             
			                        
                        			
                        		</div>
                                
                            </div> <!-- end col -->

                            
                        </div>
@endsection
                        
                        
                        

                  
            
    @section('modal')        
      <div id="role-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h4 class="modal-title" id="myModalLabel">新增角色</h4>
                  </div>
              <div class="modal-body">
                                                    
              <form class="form-horizontal" id="roleForm">                                    
                                              <div class="form-group">
                                                  <label class="col-md-2 control-label">角色编码</label>
                                                  <div class="col-md-10">
                                                      <input type="text" class="form-control" name="code" value="" required="">
                                                  </div>
                                              </div>  
                                              <div class="form-group">
                                                  <label class="col-md-2 control-label">角色名称</label>
                                                  <div class="col-md-10">
                                                      <input type="text" class="form-control" name="name" value="" required="">
                                                  </div>
                                              </div>
                                              
                                                                                                                    
                                              

                                              <div class="form-group text-center">
                                                  
                                                  
                                              </div>
                                              
                                              
                             {{csrf_field()}}
                                          </form>                                      
                                                    
                                                    
              </div>
                                                <div class="modal-footer">
                                                    <button type="button" class="btn btn-default waves-effect" data-dismiss="modal">关闭</button>
                                                    <button type="button" class="btn btn-primary btn-saveRole">保存</button>
                                                </div>
                                            </div><!-- /.modal-content -->
                                        </div><!-- /.modal-dialog -->
                                    </div><!-- /.modal -->

    @endsection        
       

           



    
        @section('js')

        <script type="text/javascript">
         

          $('#add-role').on('click',function(){
           $('#role-modal').modal('show');
          });

          $('.btn-saveRole').on('click',function(){
            var url = "{{url('zadmin/roles')}}";
            var data = $('#roleForm').serialize();
            $.post(url,data,function(rs){
              console.info(rs.data);
              if(rs.status==true) {
                var str = '<option value="'+rs.data.code+'">'+rs.data.name+'</option>';
                $('#role_code').append(str);
                $('#role-modal').modal('hide');

              }
            });  
          });
          
        </script>
        @endsection
    
